/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
 // 递归
func isValidBST(root *TreeNode) bool {
    var preNode *TreeNode
    var tarverse func (root *TreeNode) bool
    tarverse = func (root *TreeNode) bool {
        if root == nil {
            return true
        }
        leftOk := tarverse(root.Left)
        if preNode != nil && root.Val <= preNode.Val{
            return false
        }
        preNode = root
        rightOk := tarverse(root.Right)
        return leftOk && rightOk
    }
    return tarverse(root)
}
